package com.wl156.activities.order;

import java.io.IOException;

import org.ksoap2.serialization.SoapObject;
import org.xmlpull.v1.XmlPullParserException;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import com.wl156.R;
import com.wl156.activities.find.CarMessageInfo;
import com.wl156.activities.find.FindCar;
import com.wl156.activities.find.FindCarMessage;
import com.wl156.activities.find.FindCarMessageResult;
import com.wl156.activities.find.FindCarResult;
import com.wl156.activities.find.FindGood;
import com.wl156.activities.find.FindResultBase;
import com.wl156.activities.find.FindCarMessageResult.FindTask;
import com.wl156.adapters.GoodAdapter;
import com.wl156.adapters.MyPublishMessageAdapter;
import com.wl156.adapters.MyTruckMessageAdapter;
import com.wl156.adapters.TruckMessageAdapter;

public class GetMyPublishResult extends FindResultBase {

	String endLocationLv1;
	String endLocationLv2;
	String endLocationLv3;
	String truckType;
	String truckTonnage;
	String truckTonnageSymBol;
	String truckLength;
	String truckLengthSymbol;
	String setOffDate;
	String setOffDateSymbol;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mHeaderStub.setLayoutResource(R.layout.item_my_message_header);
		mHeaderStub.inflate();
		
		startLocationLv1 = "";
		startLocationLv2 = "";

//		Bundle extras = getIntent().getExtras();
//		endLocationLv1 = extras.getString("endLocationLv1");
//		endLocationLv2 = extras.getString("endLocationLv2");
//		endLocationLv3 = extras.getString("endLocationLv3");
//		truckType = extras.getString("truckType");
//		truckTonnage = extras.getString("truckTonnage");
//		truckTonnageSymBol = extras.getString("truckTonnageSymBol");
//		truckLength = extras.getString("truckLength");
//		truckLengthSymbol = extras.getString("truckLengthSymbol");
//		setOffDate = extras.getString("setOffDate");
//		setOffDateSymbol = extras.getString("setOffDateSymbol");

		hideBottomButtons();
		
		new FindTask(FindTaskBase.OTHER).execute();
		
		setTitle("我的发布");
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);

		String type = ((MyPublishMessageAdapter)mAdapter).getType(position);
		if(type.equals("货讯")) {
			Intent i = new Intent(GetMyPublishResult.this, MyGoodInfo.class);
			i.putExtra("id", id);
			i.putExtra("frommy", true);
			startActivity(i);
		} else {
			Intent i = new Intent(GetMyPublishResult.this, CarMessageInfo.class);
			i.putExtra("id", id);
			i.putExtra("frommy", true);
			startActivity(i);
		}
	}

	@Override
	protected String getFindName() {
		return "我的发布";
	}

	@Override
	protected Class getFindActivity() {
		return GetMyPublish.class;
	}

	@Override
	protected Class getFindResultActivity() {
		return GetMyPublishResult.class;
	}

	@Override
	protected int getPhoneIndex() {
		return 6;
	}

	@Override
	protected void onLastItemVisible() {
		super.onLastItemVisible();

//		new FindTask(type).execute();
	}

	public class FindTask extends FindTaskBase {
		public FindTask(int type) {
			super(type);
		}

		@Override
		protected void onLoadFailed() {
			super.onLoadFailed();

			new FindTask(type).execute();
		}

		@Override
		protected Object doInBackground(Void... params) {
			try {
				return mWebServiceClient.company_findMyMessage(mCertificate,
						mCurrentPageIndex, countPerPage);
			} catch (IOException e) {
				return e;
			} catch (XmlPullParserException e) {
				return e;
			}
		}
	}

	@Override
	protected Class getAdapter() {
		return MyPublishMessageAdapter.class;
	}

}
